124. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2023-07-12 04:42:39 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

124.1 Files compared

#LocationFileLast Modified
12023-07-12 04:42:39 +0000
2Porto v4.0.6/Theme Files/Porto Theme/app/code/Smartwave/Filterproducts/Block/WidgetCarousel.php2023-07-03 06:28:07 +0000

124.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged00
Changed00
Inserted1270
Removed00

124.3 Comparison options

WhitespaceConsecutive whitespace is treated as a single space
Character caseDifferences in character case are significant
Line endingsDifferences in line endings (CR and LF characters) are ignored
CR/LF charactersNot shown in the comparison detail
Active line-pairing rules

124.4 Active regular expressions

No regular expressions were active.

124.5 Comparison detail

    1 <?php
    2 
    3 namespace Smartwave\Filterproducts\Block\Widget;
    4 
    5 use Magento\Catalog\Api\CategoryRepositoryInterface;
    6 
    7 
    8 class Carousel extends \Magento\Catalog\Block\Product\ListProduct implements \Magento\Widget\Block\BlockInterface {
    9 
    10     protected $_collection;
    11 
    12     protected $categoryRepository;
    13 
    14     protected $_resource;
    15 
    16     protected $_pager;
    17 
    18     private $serializer;
    19 
    20     const DISPLAY_TYPE_PRODUCTS = 'latest_products';
    21 
    22     const DEFAULT_SHOW_PAGER = false;
    23 
    24     const DEFAULT_PRODUCTS_PER_PAGE = 5;
    25 
    26     const PAGE_VAR_NAME = 'np';
    27 
    28     public function __construct(
    29         \Magento\Catalog\Block\Product\Context $context,
    30         \Magento\Framework\Data\Helper\PostHelper $postDataHelper,
    31         \Magento\Catalog\Model\Layer\Resolver $layerResolver,
    32         CategoryRepositoryInterface $categoryRepository,
    33         \Magento\Framework\Url\Helper\Data $urlHelper,
    34         \Magento\Catalog\Model\ResourceModel\Product\Collection $collection,
    35         \Magento\Framework\App\ResourceConnection $resource,
    36         array $data = [],
    37         \Magento\Framework\Serialize\Serializer\Json $serializer = null
    38     ) {
    39         $this->categoryRepository = $categoryRepository;
    40         $this->_collection = $collection;
    41         $this->_resource = $resource;
    42 
    43         parent::__construct($context, $postDataHelper, $layerResolver, $categoryRepository, $urlHelper, $data);
    44 
    45         $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
    46             ->get(\Magento\Framework\Serialize\Serializer\Json::class);
    47     }
    48 
    49     protected function _beforeToHtml()
    50     {
    51         $this->setProductCollection($this->createCollection());
    52         return parent::_beforeToHtml();
    53     }
    54 
    55     public function createCollection()
    56     {
    57       $category_id = '';
    58       if($this->getData('category_ids')!=''){
    59         if(explode('/', $this->getData('category_ids'))[0] == 'category'){
    60           $category_id = explode('/', $this->getData('category_ids'))[1];
    61         }else{
    62           $category_id = $this->getData('category_ids');
    63         }
    64       }
    65       $collection = clone $this->_collection;
    66       $collection->clear()->getSelect()->reset(\Magento\Framework\DB\Select::WHERE)->reset(\Magento\Framework\DB\Select::ORDER)->reset(\Magento\Framework\DB\Select::LIMIT_COUNT)->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET)->reset(\Magento\Framework\DB\Select::GROUP);
    67       if(!$category_id) {
    68           $category_id = $this->_storeManager->getStore()->getRootCategoryId();
    69       }
    70       $category = $this->categoryRepository->get($category_id);
    71 
    72       if ($this->getData('store_id') !== null) {
    73           $collection->setStoreId($this->getData('store_id'));
    74       }
    75 
    76       $collection->addMinimalPrice()
    77           ->addFinalPrice()
    78           ->addTaxPercents()
    79           ->addAttributeToSelect('name')
    80           ->addAttributeToSelect('image')
    81           ->addAttributeToSelect('small_image')
    82           ->addAttributeToSelect('thumbnail')
    83           ->addAttributeToSelect('special_from_date')
    84           ->addAttributeToSelect('special_to_date')
    85           ->addAttributeToSelect($this->_catalogConfig->getProductAttributes())
    86           ->addUrlRewrite()
    87           ->addStoreFilter();
    88 
    89       if(isset($category) && $category)
    90       {
    91         $collection->addCategoryFilter($category);
    92       }
    93       switch ($this->getDisplayType())
    94       {
    95           case 'new_products':
    96               $collection->addAttributeToFilter(
    97                     'news_from_date',
    98                     ['date' => true, 'to' => $this->getEndOfDayDate()],
    99                     'left')
    100                 ->addAttributeToFilter(
    101                     'news_to_date',
    102                     [
    103                         'or' => [
    104                             0 => ['date' => true, 'from' => $this->getStartOfDayDate()],
    105                             1 => ['is' => new \Zend_Db_Expr('null')],
    106                         ]
    107                     ],
    108                     'left')
    109                 ->addAttributeToSort(
    110                     'news_from_date',
    111                     'desc');
    112               break;
    113           case 'featured_products':
    114               $collection->addAttributeToFilter('sw_featured', 1, 'left');
    115               break;
    116           case 'bestseller_products':
    117               $collection->getSelect()
    118                   ->joinLeft(['soi' => $collection->getTable('sales_order_item')], 'soi.product_id = e.entity_id', ['SUM(soi.qty_ordered) AS ordered_qty'])
    119                   ->join(['order' => $collection->getTable('sales_order')], "order.entity_id = soi.order_id",['order.state'])
    120                   ->where("order.state <> 'canceled' and soi.parent_item_id IS NULL AND soi.product_id IS NOT NULL")
    121                   ->group('soi.product_id')
    122                   ->order('ordered_qty DESC');
    123               break;
    124           case 'sale_products':
    125               $collection->addAttributeToFilter('special_price', ['neq' => ''])
    126               ->addAttributeToFilter(
    127                     'special_from_date',
    128                     ['date' => true, 'to' => $this->getEndOfDayDate()],
    129                     'left')
    130                 ->addAttributeToFilter(
    131                     'special_to_date',
    132                     [
    133                         'or' => [
    134                             0 => ['date' => true, 'from' => $this->getStartOfDayDate()],
    135                             1 => ['is' => new \Zend_Db_Expr('null')],
    136                         ]
    137                     ],
    138                     'left')
    139                 ->addAttributeToSort(
    140                     'news_from_date',
    141                     'desc');
    142               break;
    143           case 'deal_products':
    144               $collection->getSelect()
    145                   ->joinLeft(['dai' => $collection->getTable('sw_dailydeals_dailydeal')], 'dai.sw_product_sku = e.sku')
    146                   ->where('dai.sw_deal_enable=1')
    147                   ->where(
    148                       'dai.sw_date_from <= "'.$this->getDayDate().'" or dai.sw_date_from IS NULL'
    149                   )->where(
    150                       'dai.sw_date_to >= "'.$this->getDayDate().'" or dai.sw_date_to IS NULL'
    151                   );
    152               break;
    153           default:
    154               $collection->addAttributeToSort('created_at','desc');
    155               break;
    156       }
    157 
    158       $collection->setPageSize($this->getPageSize())
    159                  ->setCurPage($this->getCurrentPage());
    160 
    161       if($this->getDisplayType() == 'featured_products') {
    162         $collection->getSelect()->order('rand()');
    163       }
    164       return $collection;
    165     }
    166 
    167     public function getCurrentPage()
    168     {
    169         return abs((int)$this->getRequest()->getParam($this->getData('page_var_name')));
    170     }
    171 
    172     public function getCacheKeyInfo()
    173     {
    174         return array_merge(
    175             parent::getCacheKeyInfo(),
    176             [
    177                 $this->getDisplayType(),
    178                 $this->_storeManager->getStore()->getId(),
    179                 $this->getProductsPerPage(),
    180                 (int) $this->getRequest()->getParam($this->getData('page_var_name'), 1),
    181                 $this->serializer->serialize($this->getRequest()->getParams())
    182             ]
    183         );
    184     }
    185 
    186     public function getDisplayType()
    187     {
    188         if (!$this->hasData('display_type')) {
    189             $this->setData('display_type', self::DISPLAY_TYPE_PRODUCTS);
    190         }
    191         return $this->getData('display_type');
    192     }
    193 
    194     public function getProductsCount()
    195     {
    196         if (!$this->hasData('product_count')) {
    197             return parent::getProductsCount();
    198         }
    199         return $this->getData('product_count');
    200     }
    201 
    202     public function getProductsPerPage()
    203     {
    204         if (!$this->hasData('products_per_page')) {
    205             $this->setData('products_per_page', self::DEFAULT_PRODUCTS_PER_PAGE);
    206         }
    207         return $this->getData('products_per_page');
    208     }
    209 
    210     public function showPager()
    211     {
    212         return false;
    213     }
    214 
    215     protected function getPageSize()
    216     {
    217         return $this->showPager() ? $this->getProductsPerPage() : $this->getProductsCount();
    218     }
    219 
    220     public function getPagerHtml()
    221     {
    222         if ($this->showPager()) {
    223             if (!$this->_pager) {
    224                 $this->_pager = $this->getLayout()->createBlock(
    225                     \Magento\Catalog\Block\Product\Widget\Html\Pager::class,
    226                     $this->getWidgetPagerBlockName()
    227                 );
    228 
    229                 $this->_pager->setUseContainer(true)
    230                     ->setShowAmounts(true)
    231                     ->setShowPerPage(false)
    232                     ->setPageVarName($this->getData('page_var_name'))
    233                     ->setLimit($this->getProductsPerPage())
    234                     ->setTotalLimit($this->getProductsCount())
    235                     ->setCollection($this->getProductCollection());
    236             }
    237             if ($this->_pager instanceof \Magento\Framework\View\Element\AbstractBlock) {
    238                 return $this->_pager->toHtml();
    239             }
    240         }
    241         return '';
    242     }
    243 
    244     private function getWidgetPagerBlockName()
    245     {
    246         $pageName = $this->getData('page_var_name');
    247         $pagerBlockName = 'widget.porto.filter.products.carousel.pager';
    248 
    249         if (!$pageName) {
    250             return $pagerBlockName;
    251         }
    252 
    253         return $pagerBlockName . '.' . $pageName;
    254     }
    255 
    256     public function getDayDate()
    257     {
    258         return $this->_localeDate->date()->format('Y-m-d H:i:s');
    259     }
    260 
    261     public function getStartOfDayDate()
    262     {
    263         return $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s');
    264     }
    265 
    266     public function getEndOfDayDate()
    267     {
    268         return $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s');
    269     }
    270 }